<?php
header("Content-Type:text/html;charset=UTF-8");
require_once '../global.php';

function king_def(){
	global $king;
	$king->load('user');
	$userk=$king->user->infoUser(rand(12,840));
	if(empty($userk['userid'])){
		$userk=$king->user->infoUser(11);
	}
	//print_r($userk);

		$cachepath="taobaoapi/plgxid";
		if(!$plid=$king->cache->get($cachepath)){
		
			$plid=$king->db->getRows_one("select nameid from %s_pinglun order by nameid asc");
			$plid['name']=$king->db->getRows("select ktitle from %s_title_pingluen where nshow = 1");
			
			
	


				$king->cache->put($cachepath,$plid);

		}		




$kplid=$plid[nameid];




		




	if(empty($time)) $time='60';
	$cachepath="taobaoapi/plgx";
	if(!$block=$king->cache->get($cachepath,time()-$time)){
		$kuititle=$king->db->getRows_one("select * from %s_pinglun where nshow='0' and nameid >= ".$kplid." order by nameid asc,norder asc");

		$kuisz=taobaoapi_class::k_tag($kplid);
		if(empty($kuititle)){
			$kuititle['ktitle']='已经更新完毕';
		}else{
			if(!empty($kuititle['nameid']) && !empty($kuisz)){	
				

					$arrayid = count($plid['name'])-1;
					$titkid=$plid['name'][rand(0,$arrayid)][ktitle];

					$arrayid2 = count($kuisz)-1;		
					$titkid2=str_replace('图片','',$kuisz[rand(0,$arrayid2)][name]);
					$titles=str_replace('【】',"【".$titkid2."】",$titkid);
					if($kuititle['norder']=='0'){
							$array=array(

								'typeid'=>'3',		
								'userid'=>$userk['userid'],
								'username'=>$userk['username'],		
								'title'=>mb_substr(SpHtml2Text($kuititle['kcontent']),0,20,'utf-8').$titles,
								'ktag'=>keywords_class::k_dangdang_fc($kuititle['1']['0'],'2'),
								'kpath'=>'',
								'kdescription'=>SpHtml2Text($kuititle['kcontent']),
								'lastuserid'=>'11',
								'lastusername'=>$userk['username'],
								'nshow'=>'1',
								'kid'=>$kuititle['nameid'],
								'lastdate'=>time(),
							);
							

							$threadid=$king->db->insert('%s_thread',$array);
							$array=array(
								'typeid'=>'1',	
								'threadid'=>$threadid,
								'userid'=>$userk['userid'],
								'username'=>$userk['username'],	
								'ip'=>kc_getip(),
								'date'=>time(),
								'floor'=>'1',
								'nshow'=>'1',
								'kid'=>$kuititle['nameid'],
								'content'=>SpHtml2Text($kuititle['kcontent']),
							);

										
							$king->db->insert('%s_reply',$array);
							$king->db->query("delete from %s_pinglun where kid =".$kuititle['kid']);
					}else{

						
								$thred=$king->db->getRows_one("select threadid from %s_thread where kid=".$kuititle['nameid']);

								if(!empty($thred)){
								$keyrepy=$king->db->neworder('%s_reply','threadid='.$thred['threadid'],'floor');

								$userk=$king->user->infoUser(rand(12,1001));		
								$array=array(
								'typeid'=>'1',	
								'threadid'=>$thred['threadid'],
								'userid'=>$userk['userid'],
								'username'=>$userk['username'],	
								'ip'=>kc_getip(),
								'date'=>time(),
								'kid'=>$kuititle['nameid'],
								'floor'=>$keyrepy,
								'nshow'=>'1',
								'content'=>SpHtml2Text($kuititle['kcontent']),
								);
								
								$reply=$keyrepy;

								$king->db->insert('%s_reply',$array);							

								$array=array('reply'=>$reply,'hit'=>$reply*rand(2,4));
								$king->db->update('%s_thread',$array,'threadid='.$thred['threadid']);
								$king->db->query("delete from %s_pinglun where kid =".$kuititle['kid']);
								}
					}


				$king->cache->put($cachepath,'最新更新：'.$data['nameid']);


			}
		}
	}


	













}





　
?>